package Ara_Con;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import Ara_Bean.NboardBean;
import Ara_Bean.RboardBean;
import Ara_Dao.RboardDao;
import Ara_utility.Paging;

public class QboardCon implements Controller{

	private RboardDao RboardDao;
	
	public void setRboardDao(RboardDao rboardDao) {
		this.RboardDao = rboardDao;
	}
	
	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse arg1) throws Exception {
		System.out.println("in");

		List<?> totalcount = RboardDao.Qtotalcount();
		String tc = totalcount.get(0).toString().replace("{COUNT(*)=", "").replace("}", "").trim();
		
		System.out.println("totalcount " + totalcount);
		System.out.println("tc " + tc);
		String pageNumber = request.getParameter("pageNumber");
		String pageSize = request.getParameter("pageSize");
		
		Paging pageInfo = new Paging(pageNumber, pageSize, Integer.parseInt(tc), "Qcommunity_notice.rboard");
		
		RboardBean rb = new RboardBean();
		NboardBean nb = new NboardBean();
		
		rb.setBeginRow(pageInfo.getBeginRow());
		rb.setEndRow(pageInfo.getEndRow());
		
		nb.setBeginRow(pageInfo.getBeginRow());
		nb.setEndRow(pageInfo.getEndRow());
		
		List<?> rboard = RboardDao.Qcommunity_notice(rb);
		List<?> nboard = RboardDao.ncommunity_notice2(nb);
		
		System.out.println(rboard);
		System.out.println(nboard);
		
		ModelAndView mav = new ModelAndView();
		mav.addObject("Nboard",nboard);
		mav.addObject("rboard",rboard);
		mav.addObject("pageInfo", pageInfo);
		mav.setViewName("Qcommunity_notice");
		return mav;
	/*	List<?> rboard = RboardDao.rcommunity_notice();
		
		ModelAndView mav = new ModelAndView();
		mav.addObject("rboard",rboard);
		mav.setViewName("rcommunity_notice");
		
		return mav;*/
	}
	
}
